<!-- 2:实现类似田径比赛上的计时功能，
点击 开始 按钮开始计时，点击  结束按钮 停止及时，
同时页面上显示计时的秒数（以0.01秒为最小间隔单位） -->
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>计时器</title>
	</head>
	<body>
		<input type="text" value="00:00">
		<input type="button" value="开始">
		<input type="button" value="结束">
		<input type="button" value="重置">
		<script>
			var oTxt = document.getElementsByTagName("input")[0];
			var oStart = document.getElementsByTagName("input")[1];
			var oStop = document.getElementsByTagName("input")[2];
			var oReset = document.getElementsByTagName("input")[3];
			var n = 0,
				timer = null;
			oStart.onclick = function() {
				clearInterval(timer);
				timer = setInterval(function() {
					n++;
					var m = parseInt(n / 60);
					var s = parseInt(n % 60);
					oTxt.value = toDub(m) + ":" + toDub(s);
				}, 1000 / 60);
			};
			oStop.onclick = function() {
				clearInterval(timer);
			}
			oReset.onclick = function() {
				oTxt.value = "00:00";
				n = 0;
			}

			function toDub(n) {
				return n < 10 ? "0" + n : "" + n;
			}
		</script>
	</body>
</html>
